<?php

header('Content-type: text/html; charset=UTF-8');

include("../mysqlconfig.inc");

if (isset($_REQUEST['query']) && $_REQUEST['query'] != "") {
    $q = mysql_real_escape_string($_REQUEST['query']);

    $sql = "SELECT obras_nome , obras_id FROM OBRAS where locate('$q',obras_nome) > 0
    order by locate('$q',nome) limit 10";
    $r = mysql_query($sql);
    if ($r) {
        echo '<ul>' . "\n";
        while ($l = mysql_fetch_array($r)) {
            $p = $l['obra_nome'];
            $v = $l['obra_id'];
            $p = preg_replace('/(' . $q . ')/i', '<span style="font-weight:bold;">$1</span>', $p);

               echo "\t" . '<li "id="autocomplete_' . $l['nome'] . '">' . utf8_encode($p).'</li>' . "\n";


//            if($v==0){
//               echo "\t" . '<li style="color: #CC0000;"id="autocomplete_' . $l['nome'] . '">' . utf8_encode($p).'</li>' . "\n";
//            }else{
//               echo "\t" . '<li style="color: #008800;" id="autocomplete_' . $l['nome'] . '">' . utf8_encode($p).'</li>' . "\n";
//            }
        }
        echo '</ul>';
    } 
}
?>